import Vue from 'vue';
import Router from 'vue-router';
import Home from './components/Home.vue';
import About from './components/About.vue';
import Login from './components/Login.vue';
import CandidateList from './components/Candidate/CandidateList.vue';
import CreateCandidate from './components/Candidate/CreateCandidate.vue';
//基础功能
//财务管理
import Revenue from "@/components/function/Revenue.vue";
//订单明细
import Details from "./components/function/Details.vue";
//基础信息配置
import BasicInformation from "./components/function/BasicInformation.vue";
//统计分析
import OrderResponse from "@/components/Candidate/OrderResponse.vue";
//运营驾驶舱
import Tabs from "@/components/cockpit/Tabs.vue";
import Dashboard from "@/components/cockpit/Dashboard.vue";
// 用户管理
import UserControl from "@/components/function/UserControl.vue";
// 司机及车辆管理
import DriverAndCar from "@/components/function/DriverAndCar.vue";
import OrderPercentage from "@/components/cockpit/OrderPercentage.vue";
import Marketing from "@/components/Candidate/Marketing.vue";
import FlowData from "@/components/cockpit/FlowData/FlowData.vue";
import FlowDataTabs from "@/components/cockpit/FlowData/FlowDataTabs.vue";
import OrderStatistics from "@/components/cockpit/AverageDriver/OrderStatistics.vue";
import AverageDriverTabs from "@/components/cockpit/AverageDriver/AverageDriverTabs.vue";
import UserMonthly from "@/components/cockpit/MonthlyActiveUsers/UserMonthly.vue";


// 订单列表
import Dingdan from "@/components/function/Dingdan.vue";
import PaiDan from "@/components/Candidate/PaiDan.vue";
import GuiZe from "@/components/Candidate/GuiZe.vue";

Vue.use(Router);

const routes = [
    {
        path: '/user',
        name: 'UserControl',
        component: UserControl,
    },
    {
        path: '/',
        name: 'home',
        component: Home,
        // meta: { requiresAuth: true }
    },
    {
        path: '/dingdan',
        name: 'Dingdan',
        component: Dingdan,
    },
    {
        path: '/driverandcar',
        name: 'DriverAndCar',
        component: DriverAndCar,
    },
    {
        path: '/about',
        name: 'about',
        component: About,
        // meta: { requiresAuth: true }
    },
    {
        path: '/candidateList',
        name: 'CandidateList',
        component: CandidateList,
        // meta: { requiresAuth: true }
    },
    {
        path: '/marketing',
        name: 'marketing',
        component: Marketing,
    },
    {
        path: '/createCandidate',
        name: 'CreateCandidate',
        component: CreateCandidate,
        // meta: { requiresAuth: true }
    },
    {
        path: '/login',
        name: 'login',
        component: Login,
        // meta: { requiresAuth: false } // 不需要登录即可访问
    },
    //订单明细
    {
        path: '/details',
        name: 'details',
        component: Details,
        // meta: { requiresAuth: false } // 不需要登录即可访问
    },
    //财务管理
    {
        path: '/revenue',
        name: 'revenue',
        component: Revenue,
    },

    //基础信息配置
    {
        path: '/basicInformation',
        name: 'basicInformation',
        component: BasicInformation,
    },
    //统计分析
    {
        path: '/orderResponse',
        name: 'orderResponse',
        component: OrderResponse,
    },
    // 运营驾驶舱
    {
        path: '/tabs',
        name: 'tabs',
        component: Tabs,
        // meta: { requiresAuth: true }
    },
    {
        path: '/dashboard',
        name: 'dashboard',
        component: Dashboard,
        // meta: { requiresAuth: true }
    },
    {
        path: '/orderPercentage',
        name: 'orderPercentage',
        component: OrderPercentage,
        // meta: { requiresAuth: true }
    },
    {
        path: '/flowData',
        name: 'flowData',
        component: FlowData,
        // meta: { requiresAuth: true }
    },
    {
        path: '/flowDataTabs',
        name: 'flowDataTabs',
        component: FlowDataTabs,
        // meta: { requiresAuth: true }
    },
    {
        path: '/orderStatistics',
        name: 'orderStatistics',
        component: OrderStatistics,
        // meta: { requiresAuth: true }
    },
    {
        path: '/averageDriverTabs',
        name: 'averageDriverTabs',
        component: AverageDriverTabs,
        // meta: { requiresAuth: true }
    },
    {
        path: '/userMonthly',
        name: 'userMonthly',
        component: UserMonthly,
        // meta: { requiresAuth: true }
    },
    {
        path: '/paidan',
        name: 'paidan',
        component: PaiDan,
        // meta: { requiresAuth: true }
    },
    {
        path: '/guize',
        name: 'guize',
        component: GuiZe,
        // meta: { requiresAuth: true }
    },
];

const router = new Router({
    routes
});

// 全局路由守卫，用于判断登录状态并决定是否允许访问页面
router.beforeEach((to, from, next) => {
    const isLoggedIn = localStorage.getItem('isLoggedIn'); // 模拟从本地存储获取登录状态，实际可替换为与后端验证的逻辑
    if (to.meta.requiresAuth && !isLoggedIn) {
        next('/login'); // 如果需要登录但未登录，跳转到登录页面
    } else {
        next();
    }
});

export default router;
